package com.woniuxy.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.woniuxy.entity.*;
import com.woniuxy.service.AfterLoanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/afterLoan")
public class AfterLoanController extends BaseController {
    @Autowired
    private AfterLoanService afterLoanService;

    // 还款管理list和query
    @GetMapping("/listRepayment")
    public TableDataInfo listRepayment(){
        startPage();
        List<UserYewuDate> list = afterLoanService.listRepayment();
        return getDataTable(list) ;
    }

    @PostMapping("/queryRepayment")
    public TableDataInfo queryRepayment(@RequestBody BeforeQueryData data){
        startPage();
        if(data.getDates()!=null){
            if(data.getDates().length==0){
                data.setDates(null);
            }
        }
        List<UserYewuDate> list = afterLoanService.queryRepayment(data);
        return getDataTable(list) ;
    }

    // 贷后检查记录表的list和query
    @GetMapping("/listCheckUp")
    public TableDataInfo listCheckUp(){
        startPage();
        List<LoanCheckData> list = afterLoanService.listCheckUp();
        return getDataTable(list) ;
    }


    @PostMapping("/queryCheckUp")
    public TableDataInfo queryCheckUp(@RequestBody BeforeQueryData datas){
        if(datas.getDates()!=null){
            if(datas.getDates().length==0){
                datas.setDates(null);
            }
        }
        startPage();
        List<LoanCheckData> list = afterLoanService.queryCheckUp(datas);
        return getDataTable(list) ;
    }

    // 利率变更表的list和query
    @GetMapping("/listRateLog")
    public TableDataInfo listRateLog(){
        startPage();
        List<LoanRateChangeData> list = afterLoanService.listRateLog();
        return getDataTable(list) ;
    }


    @PostMapping("/queryRateLog")
    public TableDataInfo queryRateLog(@RequestBody BeforeQueryData datas){
        if(datas.getDates()!=null){
            if(datas.getDates().length==0){
                datas.setDates(null);
            }
        }
        startPage();
        List<LoanRateChangeData> list = afterLoanService.queryRateLog(datas);
        return getDataTable(list) ;
    }

    //贷后预警表的
    @GetMapping("/listLoanWarning")
    public TableDataInfo listLoanWarning(){
        startPage();
        List<LoanWarningData> list = afterLoanService.listLoanWarning();
        return getDataTable(list) ;
    }


    @PostMapping("/queryLoanWarning")
    public TableDataInfo queryLoanWarning(@RequestBody BeforeQueryData datas){
        if(datas.getDates()!=null){
            if(datas.getDates().length==0){
                datas.setDates(null);
            }
        }
        startPage();
        List<LoanWarningData> list = afterLoanService.queryLoanWarning(datas);
        return getDataTable(list) ;
    }

    //结项的那个玩意
    @GetMapping("/listLoanEnd")
    public TableDataInfo listLoanEnd(){
        startPage();
        List<UserYewuDate> list = afterLoanService.listLoanEnd();
        return getDataTable(list) ;
    }


    @PostMapping("/queryLoanEnd")
    public TableDataInfo queryLoanEnd(@RequestBody BeforeQueryData datas){
        if(datas.getDates()!=null){
            if(datas.getDates().length==0){
                datas.setDates(null);
            }
        }
        startPage();
        List<UserYewuDate> list = afterLoanService.queryLoanEnd(datas);
        return getDataTable(list) ;
    }

    @PutMapping("/updateWarningType/{loansId}/{type}")
    public R updateWarningType(@PathVariable int loansId,@PathVariable String type){
        startPage();
        int row  = afterLoanService.updateWarningType(loansId,type);
        return R.ok() ;
    }
}
